package com.herohead.pushco;

import java.util.Set;

import redis.clients.jedis.Jedis;

import com.herohead.redis.GetRedisServer;
import com.herohead.redis.getConfig;

public class KeyRing {

	@SuppressWarnings("rawtypes")
	Set keyring;
	String redisHost;
	Jedis jd;
	String redisPushcoKeys =  "prod:pushco:apikeys";

	String strKey;
	String apiKey;
	String apiSecret;


	public KeyRing() {
		GetRedisServer getredis = new GetRedisServer();
		redisHost = getredis.getRedisHost();
	}
	public KeyRing(String key) {
		loadkeyNames();
		getKey(key);
	}

	public String getApiKey(String key) {
		return apiKey;
	}

	public void getKey(String key){

		strKey = jd.hget(redisPushcoKeys, key);

		try {
			apiKey = getConfig.getValueJson(strKey, "apiKey");
			apiSecret = getConfig.getValueJson(strKey, "apiSecret");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
			System.out.println("Problem finding keys in REDIS Server called keys: " + key);
			System.out.println("Program is ending");
		}
	}

	@SuppressWarnings("rawtypes")
	public Set getKeyNames() {
		loadkeyNames();
		return keyring;
	}

	public String getSecretKey(String key) {
		return apiSecret;

	}

	public void loadkeyNames() {
		GetRedisServer getredis = new GetRedisServer();
		redisHost = getredis.getRedisHost();


		jd = new Jedis(redisHost);

		Set<String> s = jd.hkeys(redisPushcoKeys);
		keyring = s;
	}

}
